package com.softer.chengxin.home.controller;

import com.softer.chengxin.home.domin.Street;
import com.softer.chengxin.home.service.StreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2018/10/18
 */
@RestController
public class StreetController {
    @Autowired
    private StreetService streetService;

    /**
     * 加载街道列表
     *
     * @return 列表
     */
    @PostMapping("/api/street/loadStreet")
    public List<Street> loadStreet() {
        return streetService.loadStreet();
    }

    /**
     * 根据登陆用户，选择街道列表
     * @param session 缓存
     * @return 列表
     */
    @PostMapping("/api/street/loadUserStreet")
    public List<Street> loadStreetByUser(HttpSession session){
        //  查询登陆ID
        Integer id = (Integer) session.getAttribute("ID");
        if (id == null) {
            return new ArrayList<>();
        }
        return streetService.loadStreetByUser(id);
    }
}
